package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.Permission;
import com.itheima.service.PermissionService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/permission")
public class PermissionController {

    @Reference
    private PermissionService permissionService;

    @RequestMapping("/findPage")
    public Result findAll(@RequestBody QueryPageBean queryPageBean) {
        try {
            PageResult pr = permissionService.findAll(queryPageBean);
            return new Result(true, "权限查询成功! ", pr);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(true, "权限查询失败! ");
        }
    }

    @RequestMapping("/addPermission")
    public Result addPermission(@RequestBody Permission permission) {
        try {
            permissionService.addPermission(permission);
            return new Result(true, "权限添加成功! ");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, "权限添加失败! ");
        }
    }

}
